package org.webscale.util;

import java.io.Serializable;
/**
 * An Object Representing Name and Value Pair 
 * @author Niraj
 */
public class NameValuePair implements Serializable {

	private static final long serialVersionUID = 1L;
	private String name ;
	private String value;
	/**
	 * expects nXXX=ssss;
	 * if not found then returns NameValue object with name = xx and value = txt
	 * @param txt
	 * @return
	 */
	public static NameValuePair parse(String txt){
		String [] str = txt.split("=");
		NameValuePair nv = new NameValuePair();
		if(str.length == 2){
			nv.setName(str[0].trim());
			nv.setValue(str[1].trim());
		}
		else {
			nv.setName("xx");
			nv.setValue(str[0].trim());
		}
		return nv;
	}
	
	public NameValuePair() {
		super();
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	@Override
	public boolean equals(Object obj) {
		NameValuePair nv = (NameValuePair)obj;
		if(nv.getValue()!= getValue()){
			return false;
		}else if(nv.getName() != nv.getName()){
			return false;
		}else
			return true;
	
	}
	
	
}
